<?php
/**
 * Created by PhpStorm.
 * User: titarzhe
 * Date: 18-4-18
 * Time: 上午9:15
 */
namespace AppBundle\Helper;
use Symfony\Component\Templating\Helper\Helper;
use Symfony\Component\HttpFoundation\Session\SessionInterface;

class UserHelper extends Helper{

    protected $value = '';
    protected $user = null;
    protected $session;
    public function __construct(SessionInterface $session)
    {
        $this->session = $session;
    }

    public function __toString()
    {
        if($this->session->has('user')){
            $user = $this->session->get('user');
            return $user->getUsername();
        }else{
            return '';
        }
    }

    public function getName()
    {
        return 'user_helper';
    }
}